// websocket.js  
const WebSocket = require('ws');  

const createWebSocketServer = (httpServer) => {  
  const wss = new WebSocket.Server({ server: httpServer });  

  wss.on('connection', (ws) => {  
    console.log('Client connected');  

    ws.on('message', (message) => {  
      console.log(`Received: ${message}`);  
      // Echo the received message back to the client  
      ws.send(`Echo: ${message}`);  
    });  

    ws.on('close', () => {  
      console.log('Client disconnected');  
    });  
  });  

  return wss;  
};  

module.exports = createWebSocketServer;  